package com.sgb.kjwl.view.ui.fragment.manage;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.google.android.material.tabs.TabLayout;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FrIntellectualPropertyForWebsiteBinding;
import com.sgb.kjwl.di.manage.DaggerEnterpriseManageFragComponent;
import com.sgb.kjwl.di.manage.EnterpriseManageFragModule;
import com.swgk.core.util.PickSelectEntity;
import com.sgb.kjwl.model.entity.manage.IPDetailEntity;
import com.sgb.kjwl.view.ui.activity.manage.IPActivity;
import com.sgb.kjwl.view.ui.activity.manage.IPDetailActivity;
import com.sgb.kjwl.view.ui.adapter.manage.DataForCompanyShopAdapter;
import com.sgb.kjwl.view.widget.EnterprisePopWindow;
import com.sgb.kjwl.view.widget.IPRPopWindow;
import com.sgb.kjwl.view.widget.manage.TheEnterpriseOfAreaPopWindow;
import com.sgb.kjwl.viewmodel.manage.IntellectualPropertyForWebsiteModel;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;
import com.swgk.core.util.ClickUtils;
import com.swgk.core.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

/*
 * Author LiWei
 * Create Time 2021/4/15
 * Description 网站-知识产权
 * */
public class IntellectualPropertyForWebsite extends AppLazyFragment {

    @Inject
    IntellectualPropertyForWebsiteModel viewModel;
    private FrIntellectualPropertyForWebsiteBinding binding;

    private String websiteNo;
    private int websiteType;

    public static final String KEY_BRAND = "商标";
    public static final String KEY_PATENT = "专利";
    public static final String KEY_COPYRIGHT = "版权";
    private List<PickSelectEntity> mTypeData = new ArrayList<>();
    private List<PickSelectEntity> typeBrand = new ArrayList<>();//商标
    private List<PickSelectEntity> typePatent = new ArrayList<>();//专利
    private List<PickSelectEntity> typeCopyright = new ArrayList<>();//版权
    private List<PickSelectEntity> typeNormal = new ArrayList<>();
    private String type;
    private boolean isLoadMore;
    private DataForCompanyShopAdapter ipAdapter;
    private IPRPopWindow pickOnePopWindow;
    private int page = 1;
    private int position1;//商标分类position
    private int position2;//商标状态position
    private int position3;//专利分类position
    private int position4;//专利状态position
    private int position5;//版权分类position
    private int position6;//版权状态position
    private boolean isStatus = false;
    private String tag;
    private String state;
    private Map<String, String> stringMap = new HashMap<>();
    private boolean change1, change2, change3, change4, change5, change6;//用于判断三种类型六个tag的标记样式

    private EnterprisePopWindow tradeCategoryWindow;//行业类型
    private EnterprisePopWindow fieldCategoryWindow;//领域分类
    private EnterprisePopWindow patentStateWindow;//专利状态
    private TheEnterpriseOfAreaPopWindow areaPopWindow;//地区弹窗
    private TheEnterpriseOfAreaPopWindow areaPopWindow2;//地区弹窗

    private List<PickSelectEntity> mTradeCategoryData = new ArrayList<>();//行业类型
    private List<PickSelectEntity> mFieldCategoryData = new ArrayList<>();//领域分类
    private List<PickSelectEntity> mPatentStateData = new ArrayList<>();//专利状态
    private List<PickSelectEntity> provinceData = new ArrayList<>();//省数据
    private List<PickSelectEntity> cityData = new ArrayList<>();//市数据
    private List<PickSelectEntity> provinceData2 = new ArrayList<>();//省数据
    private List<PickSelectEntity> cityData2 = new ArrayList<>();//市数据

    //省
    private String provinceNo = "";
    //地区
    private String mCityNo = "";
    //省
    private String provinceNo2 = "";
    //地区
    private String mCityNo2 = "";

    private String name2 = "";
    private String name3 = "";
    private String name4 = "";
    private String name5 = "";
    Map<String, Object> mapBrand = new HashMap<>();
    Map<String, Object> mapPatent = new HashMap<>();
    Map<String, Object> mapCopyright = new HashMap<>();

    private String tradeType1 = "";
    private String tradeType2 = "";
    private String tradeType3 = "";
    private int tradeTypePosition1 = 0;
    private int tradeTypePosition2 = 0;
    private int tradeTypePosition3 = 0;

    private boolean isMyself;
    public static final String TYPE_IS_MYSELF = "type_is_myself"; //是不是当前身份的网站

    public static IntellectualPropertyForWebsite newInstance(String websiteNo, int websiteType, boolean isMySelf) {
        IntellectualPropertyForWebsite fragment = new IntellectualPropertyForWebsite();
        Bundle args = new Bundle();
        args.putString("websiteNo", websiteNo);
        args.putInt("websiteType", websiteType);
        args.putBoolean(TYPE_IS_MYSELF, isMySelf);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        super.setupFragmentComponent(appComponent);
        DaggerEnterpriseManageFragComponent.builder().appComponent(appComponent)
                .enterpriseManageFragModule(new EnterpriseManageFragModule(this))
                .build()
                .inject(this);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fr_intellectual_property_for_website, container, false);
        if (getArguments() != null) {
            websiteNo = getArguments().getString("websiteNo");
            websiteType = getArguments().getInt("websiteType");
            isMyself = getArguments().getBoolean(TYPE_IS_MYSELF);
        }
        return binding.getRoot();
    }

    @Override
    protected void initView() {
        binding.tvStatus.setOnClickListener(this);
        binding.tvType.setOnClickListener(this);
        binding.tvSort.setOnClickListener(this);

        binding.tvTradeCategory.setOnClickListener(this);
        binding.tvFieldCategory.setOnClickListener(this);
        binding.tvPatentState.setOnClickListener(this);
        binding.tvPlace.setOnClickListener(this);
        binding.tvPlace2.setOnClickListener(this);

        if (isMyself){
            type = KEY_BRAND;
            binding.tablayout.addTab(binding.tablayout.newTab().setText(KEY_BRAND));
            binding.tablayout.addTab(binding.tablayout.newTab().setText(KEY_PATENT));
            binding.tablayout.addTab(binding.tablayout.newTab().setText(KEY_COPYRIGHT));
        }
        binding.tablayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @RequiresApi(api = Build.VERSION_CODES.M)
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                type = tab.getText().toString();
                mapBrand.put("typesOfPropertyRights", type);
                binding.tvSort.setText("行业分类");
                setTag();
                setTradeCategoryWindowState();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        //默认商标
        mapBrand.put("typesOfPropertyRights", "商标");

        if (ipAdapter == null) {
            ipAdapter = new DataForCompanyShopAdapter(getActivity(), null);
        }
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        binding.recyclerView.setLayoutManager(layoutManager);
        binding.recyclerView.setAdapter(ipAdapter);
        binding.recyclerView.setLoadingMoreEnabled(true);
        binding.recyclerView.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {
                isLoadMore = false;
                page = 1;
                getData(page);
            }

            @Override
            public void onLoadMore() {
                isLoadMore = true;
                page = page + 1;
                getData(page);
            }
        });

        ipAdapter.setOnItemClick(new AdapterOnItemClick<IPDetailEntity>() {
            @Override
            public void onItemClick(IPDetailEntity ipDetailEntity, int position) {
                IPDetailActivity.startAction(getActivity(), ipDetailEntity);
            }
        });
        pickOnePopWindow = new IPRPopWindow(getActivity());
        pickOnePopWindow.setOnResultClick(new BasePopWindow.OnResultClick() {
            @RequiresApi(api = Build.VERSION_CODES.M)
            @Override
            public void result(Object key1, Object key2, Object key3) {
                if (KEY_BRAND.equals(type)) {
                    if (isStatus) {
                        position2 = (Integer) key3;
                        state = typeNormal.get(position2).getNo();
                    } else {
                        position1 = (Integer) key3;
                        tag = key2.toString();
                        stringMap.put(type, tag);
                        mapBrand.put("type", tag.equals("不限") ? "" : tag);
                    }
                } else if (KEY_PATENT.equals(type)) {
                    if (isStatus) {
                        position4 = (Integer) key3;
                        state = typeNormal.get(position4).getNo();
                    } else {
                        position3 = (Integer) key3;
                        tag = key2.toString();
                        stringMap.put(type, tag);
                        mapPatent.put("type", tag.equals("不限") ? "" : tag);
                    }
                } else {
                    if (isStatus) {
                        position6 = (Integer) key3;
                        state = typeNormal.get(position6).getNo();
                    } else {
                        position5 = (Integer) key3;
                        tag = key2.toString();
                        stringMap.put(type, tag);
                        mapCopyright.put("type", tag.equals("不限") ? "" : tag);
                    }
                }
                setTag();
            }
        });
        pickOnePopWindow.setOnDismissListener(() -> {
            if (KEY_BRAND.equals(type)) {
                if (isStatus) {
                    if (!change1) {
                        binding.tvStatus.setTextColor(getResources().getColor(R.color.color_333333));
                        setDrwImage(binding.tvStatus, 2);
                    } else {
                        setDrwImage(binding.tvStatus, 1);
                    }
                } else {
                    if (!change2) {
                        binding.tvType.setTextColor(getResources().getColor(R.color.color_333333));
                        setDrwImage(binding.tvType, 2);
                    } else {
                        setDrwImage(binding.tvType, 1);
                    }
                }
            } else if (KEY_PATENT.equals(type)) {
                if (isStatus) {
                    if (!change3) {
                        binding.tvStatus.setTextColor(getResources().getColor(R.color.color_333333));
                        setDrwImage(binding.tvStatus, 2);
                    } else {
                        setDrwImage(binding.tvStatus, 1);
                    }
                } else {
                    if (!change4) {
                        binding.tvType.setTextColor(getResources().getColor(R.color.color_333333));
                        setDrwImage(binding.tvType, 2);
                    } else {
                        setDrwImage(binding.tvType, 1);
                    }
                }
            } else {
                if (isStatus) {
                    if (!change5) {
                        binding.tvStatus.setTextColor(getResources().getColor(R.color.color_333333));
                        setDrwImage(binding.tvStatus, 2);
                    } else {
                        setDrwImage(binding.tvStatus, 1);
                    }
                } else {
                    if (!change6) {
                        binding.tvType.setTextColor(getResources().getColor(R.color.color_333333));
                        setDrwImage(binding.tvType, 2);
                    } else {
                        setDrwImage(binding.tvType, 1);
                    }
                }
            }
        });
        pickOnePopWindow.setDefData(0);

        //行业类型
        tradeCategoryWindow = new EnterprisePopWindow(getActivity());
        tradeCategoryWindow.setBgView(binding.grayLayout);
        tradeCategoryWindow.setOnResultClick((key1, key2, key3) -> {
            switch (type) {
                case KEY_BRAND:
                    tradeType1 = (String) key2;
                    tradeTypePosition1 = (int) key3;
                    //请求接口
                    mapBrand.put("honorNo", key1);
                    viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
                    break;
                case KEY_PATENT:
                    tradeType2 = (String) key2;
                    tradeTypePosition2 = (int) key3;
                    //请求接口
                    mapPatent.put("honorNo", key1);
                    viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
                    break;
                case KEY_COPYRIGHT:
                    tradeType3 = (String) key2;
                    tradeTypePosition3 = (int) key3;
                    //请求接口
                    mapCopyright.put("honorNo", key1);
                    viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
                    break;
            }
        });
        tradeCategoryWindow.setOnDisMissClick(() -> setTradeCategoryWindowState());

        //领域分类
        fieldCategoryWindow = new EnterprisePopWindow(getActivity());
        fieldCategoryWindow.setBgView(binding.grayLayout);
        fieldCategoryWindow.setOnResultClick((key1, key2, key3) -> {
            name2 = (String) key2;
            //请求接口
            mapPatent.put("fieldClassId", key1);
            viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
        });
        fieldCategoryWindow.setOnDisMissClick(() -> {
            if (name2.equals("") || name2.equals("不限")) {
                binding.tvFieldCategory.contentSelect(false, false);
            } else {
                binding.tvFieldCategory.contentSelect(true, false);
            }
        });

        //专利状态
        patentStateWindow = new EnterprisePopWindow(getActivity());
        patentStateWindow.setBgView(binding.grayLayout);
        patentStateWindow.setOnResultClick((key1, key2, key3) -> {
            name3 = (String) key2;
            //请求接口
            mapPatent.put("state", key1);
            viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
        });
        patentStateWindow.setOnDisMissClick(() -> {
            if (name3.equals("") || name3.equals("不限")) {
                binding.tvPatentState.contentSelect(false, false);
            } else {
                binding.tvPatentState.contentSelect(true, false);
            }
        });

        // 省 城市
        areaPopWindow = new TheEnterpriseOfAreaPopWindow(getActivity());
        areaPopWindow.setBgView(binding.grayLayout);
        areaPopWindow.isVisibleBottomLayout(false);
        areaPopWindow.setOnResultClick((key1, key2, key3) -> {
            boolean isProvince = (boolean) key3;
            switch (type) {
                case KEY_BRAND:
                    if (isProvince) {
                        provinceNo = (String) key1;
                        mCityNo = "";
                        mapBrand.put("provinceNo", provinceNo);
                    } else {
                        mCityNo = (String) key1;
                    }
                    name4 = (String) key2;
                    mapBrand.put("cityNo", mCityNo);
                    viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
                    break;
                case KEY_COPYRIGHT:
                    if (isProvince) {
                        provinceNo = (String) key1;
                        mCityNo = "";
                        mapCopyright.put("provinceNo", provinceNo);
                    } else {
                        mCityNo = (String) key1;
                    }
                    name4 = (String) key2;
                    mapCopyright.put("cityNo", mCityNo);
                    viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
                    break;
            }
        });
        areaPopWindow.setOnDisMissClick(() -> {
            if (name4.equals("") || name4.equals("不限") && !(!provinceNo.equals("") && mCityNo.equals(""))) {
                binding.tvPlace.contentSelect(false, false);
            } else {
                binding.tvPlace.contentSelect(true, false);
            }
            if (provinceNo.equals("")) {
                binding.tvPlace.contentSelect(false, false);
            }
        });
        areaPopWindow.setiButtonClick(no -> viewModel.getCityData(no));

        // 省 城市
        areaPopWindow2 = new TheEnterpriseOfAreaPopWindow(getActivity());
        areaPopWindow2.setBgView(binding.grayLayout);
        areaPopWindow2.isVisibleBottomLayout(false);
        areaPopWindow2.setOnResultClick((key1, key2, key3) -> {
            boolean isProvince2 = (boolean) key3;
            if (isProvince2) {
                provinceNo2 = (String) key1;
                mCityNo2 = "";
                mapCopyright.put("provinceNo", provinceNo2);
            } else {
                mCityNo2 = (String) key1;
            }
            name5 = (String) key2;
            mapCopyright.put("cityNo", mCityNo2);
            viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
        });
        areaPopWindow2.setOnDisMissClick(() -> {
            if (name5.equals("") || name5.equals("不限") && !(!provinceNo2.equals("") && mCityNo2.equals(""))) {
                binding.tvPlace2.contentSelect(false, false);
            } else {
                binding.tvPlace2.contentSelect(true, false);
            }
            if (provinceNo2.equals("")) {
                binding.tvPlace2.contentSelect(false, false);
            }
        });
        areaPopWindow2.setiButtonClick(no -> viewModel.getCityData2(no));

        init();
        if (!isMyself) {
            viewModel.mMenus.observe(this, new Observer<List<PickSelectEntity>>() {
                @Override
                public void onChanged(List<PickSelectEntity> pickSelectEntities) {
                    binding.tablayout.removeAllTabs();
                    if (pickSelectEntities != null) {
                        for (PickSelectEntity entity : pickSelectEntities) {
                            if (entity.getProjectscale().equals(KEY_BRAND)) {
                                binding.tablayout.addTab(binding.tablayout.newTab().setText(KEY_BRAND));
                            }
                            if (entity.getProjectscale().equals(KEY_PATENT)) {
                                binding.tablayout.addTab(binding.tablayout.newTab().setText(KEY_PATENT));
                            }
                            if (entity.getProjectscale().equals(KEY_COPYRIGHT)) {
                                binding.tablayout.addTab(binding.tablayout.newTab().setText(KEY_COPYRIGHT));
                            }
                        }
                        if (binding.tablayout.getTabCount() > 0) {
                            type = binding.tablayout.getTabAt(0).getText().toString();
                        }
                        setTag();
                    }
                }
            });
        }
    }

    private void init() {
        typeNormal.add(new PickSelectEntity("", "不限"));
        typeNormal.add(new PickSelectEntity("1", "独家"));
        typeNormal.add(new PickSelectEntity("2", "非独家"));
    }


    @Override
    protected void onLazyLoad() {
        if (!isMyself){
            viewModel.getSecondMenus(websiteNo, websiteType + "");
        } else {
            setTag();
        }
    }

    private void setTradeCategoryWindowState() {
        switch (type) {
            case KEY_BRAND:
                if (tradeType1.equals("") || tradeType1.equals("不限")) {
                    binding.tvTradeCategory.contentSelect(false, false);
                } else {
                    binding.tvTradeCategory.contentSelect(true, false);
                }
                tradeCategoryWindow.setDefData(tradeTypePosition1);
                break;
            case KEY_PATENT:
                if (tradeType2.equals("") || tradeType2.equals("不限")) {
                    binding.tvTradeCategory.contentSelect(false, false);
                } else {
                    binding.tvTradeCategory.contentSelect(true, false);
                }
                tradeCategoryWindow.setDefData(tradeTypePosition2);
                break;
            case KEY_COPYRIGHT:
                if (tradeType3.equals("") || tradeType3.equals("不限")) {
                    binding.tvTradeCategory.contentSelect(false, false);
                } else {
                    binding.tvTradeCategory.contentSelect(true, false);
                }
                tradeCategoryWindow.setDefData(tradeTypePosition3);
                break;
        }
    }

    private void setTag() {
        isLoadMore = false;
        binding.tvType.setText(type + "类型");
        if (TextUtils.isEmpty(stringMap.get(type)) || "不限".equals(stringMap.get(type))) {
            tag = "";
            setTextViewBg(binding.tvType, R.drawable.search_bg, R.mipmap.ic_down_arrow_n, R.color.color_333333);
            setDrwImage(binding.tvType, 2);
            if (KEY_BRAND.equals(type)) {
                change2 = false;
            } else if (KEY_PATENT.equals(type)) {
                change4 = false;
            } else {
                change6 = false;
            }
        } else {
            setTextViewBg(binding.tvType, R.drawable.search_new_blue_bg, R.mipmap.icon_down_red, R.color.color_main);
            tag = stringMap.get(type);
            if (KEY_BRAND.equals(type)) {
                change2 = true;
            } else if (KEY_PATENT.equals(type)) {
                change4 = true;
            } else {
                change6 = true;
            }
        }
        if (KEY_BRAND.equals(type)) {
            state = typeNormal.get(position2).getNo();
        } else if (KEY_PATENT.equals(type)) {
            state = typeNormal.get(position4).getNo();
        } else {
            state = typeNormal.get(position6).getNo();
        }
        binding.tvStatus.setText(type + "状态");
        if (TextUtils.isEmpty(state)) {
            setTextViewBg(binding.tvStatus, R.drawable.search_bg, R.mipmap.ic_down_arrow_n, R.color.color_333333);
            setDrwImage(binding.tvStatus, 2);
            if (KEY_BRAND.equals(type)) {
                change1 = false;
            } else if (KEY_PATENT.equals(type)) {
                change3 = false;
            } else {
                change5 = false;
            }
        } else {
            binding.tvStatus.setTextColor(ContextCompat.getColor(getActivity(), R.color.color_tab_one));
            setTextViewBg(binding.tvStatus, R.drawable.search_bg, R.mipmap.ic_down_arrow_n, R.color.color_tab_one);
            if (KEY_BRAND.equals(type)) {
                change1 = true;
            } else if (KEY_PATENT.equals(type)) {
                change3 = true;
            } else {
                change5 = true;
            }
        }
        switch (type) {
            case KEY_BRAND:
                binding.tvFieldCategory.setVisibility(View.GONE);
                binding.tvPatentState.setVisibility(View.GONE);
                binding.tvPlace.setVisibility(View.VISIBLE);
                binding.tvPlace2.setVisibility(View.GONE);
                break;
            case KEY_PATENT:
                binding.tvFieldCategory.setVisibility(View.VISIBLE);
                binding.tvPatentState.setVisibility(View.VISIBLE);
                binding.tvPlace.setVisibility(View.GONE);
                binding.tvPlace2.setVisibility(View.GONE);
                break;
            case KEY_COPYRIGHT:
                binding.tvFieldCategory.setVisibility(View.GONE);
                binding.tvPatentState.setVisibility(View.GONE);
                binding.tvPlace.setVisibility(View.GONE);
                binding.tvPlace2.setVisibility(View.VISIBLE);
                break;
        }
        getData(1);
    }

    private void getData(int page) {
        switch (type) {
            case KEY_BRAND:
                mapBrand.put("page", page);
//                mapBrand.put("name", searchName);
                mapBrand.put("typesOfPropertyRights", type);
                mapBrand.put("limit", 20);
//                mapBrand.put("type", tag);
//                mapBrand.put("state", state);
                viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
                break;
            case KEY_PATENT:
                mapPatent.put("page", page);
//                mapPatent.put("name", searchName);
                mapPatent.put("typesOfPropertyRights", type);
                mapPatent.put("limit", 20);
//                mapPatent.put("type", tag);
//                mapPatent.put("state", state);
                viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
                break;
            case KEY_COPYRIGHT:
                mapCopyright.put("page", page);
//                mapCopyright.put("name", searchName);
                mapCopyright.put("typesOfPropertyRights", type);
                mapCopyright.put("limit", 20);
//                mapCopyright.put("type", tag);
//                mapCopyright.put("state", state);
                viewModel.getIntellectualPropertyList(websiteNo, websiteType, mapBrand);
                break;
        }
    }

    public void setTypeDatas(List<PickSelectEntity> datas, boolean isStatus) {
        mTypeData.clear();
        if (KEY_BRAND.equals(type)) {
            if (!isStatus) {
                pickOnePopWindow.setDefData(position1);
                typeBrand = datas;
            } else {
                pickOnePopWindow.setDefData(position2);
            }
        } else if (KEY_PATENT.equals(type)) {
            if (!isStatus) {
                typePatent = datas;
                pickOnePopWindow.setDefData(position3);
            } else {
                pickOnePopWindow.setDefData(position4);
            }
        } else {
            if (!isStatus) {
                pickOnePopWindow.setDefData(position5);
                typeCopyright = datas;
            } else {
                pickOnePopWindow.setDefData(position6);
            }
        }
        mTypeData.addAll(datas);

        pickOnePopWindow.showAsDropDown(binding.layoutTag, 0, 0);
        pickOnePopWindow.setData(mTypeData);
    }

    public void showList(List<IPDetailEntity> list) {
        binding.recyclerView.refreshComplete();
        if (isLoadMore) {
            binding.recyclerView.loadMoreComplete();
            if (list.size() > 0) {
                ipAdapter.addDatas(list);
            } else {
                binding.recyclerView.setNoMore(true);
            }
            binding.recyclerView.setVisibility(View.VISIBLE);
        } else {
            if (list.size() > 0) {
                binding.recyclerView.setVisibility(View.VISIBLE);
                binding.empty2.emptyView.setVisibility(View.GONE);
                ipAdapter.setDatas(list);
                binding.recyclerView.setLoadingMoreEnabled(true);
            } else {
                ipAdapter.setDatas(null);
                binding.recyclerView.setVisibility(View.GONE);
                binding.empty2.emptyView.setVisibility(View.VISIBLE);
            }
        }
    }

    @Override
    public void onMultiClick(View v) {
        super.onMultiClick(v);
        switch (v.getId()) {
            case R.id.right_view:
                break;
            case R.id.tv_cancel:
                break;
            case R.id.tv_status:
                if (!pickOnePopWindow.isShowing()) {
                    setDrwImage(binding.tvStatus, 0);
                    binding.tvStatus.setTextColor(getResources().getColor(R.color.color_main));
                }
                isStatus = true;
                if (!ClickUtils.isDoubleClick()) {
                    pickOnePopWindow.dismiss();
                    setTypeDatas(typeNormal, isStatus);
                }
                break;
            case R.id.tv_type:
                if (!pickOnePopWindow.isShowing()) {
                    setDrwImage(binding.tvType, 0);
                    binding.tvType.setTextColor(getResources().getColor(R.color.color_main));
                }
                isStatus = false;
                if (!ClickUtils.isDoubleClick()) {
                    pickOnePopWindow.dismiss();
                    if (KEY_BRAND.equals(type)) {
                        if (null != typeBrand && typeBrand.size() > 0) {
                            setTypeDatas(typeBrand, false);
                        } else {
                            viewModel.getTrademarkType();
                        }
                    } else if (KEY_PATENT.equals(type)) {
                        if (null != typePatent && typePatent.size() > 0) {
                            setTypeDatas(typePatent, false);
                        } else {
                            viewModel.getPatentType();
                        }
                    } else {
                        if (null != typeCopyright && typeCopyright.size() > 0) {
                            setTypeDatas(typeCopyright, isStatus);
                        } else {
                            viewModel.getRightType();
                        }
                    }
                }
                break;
            case R.id.tv_trade_category:
                if (!ClickUtils.isDoubleClick()) {
                    binding.tvTradeCategory.contentSelect(false, true);
                    if (mTradeCategoryData.size() == 0) {
                        viewModel.getTradeCategory();
                    } else {
                        showTradeCategoryPopWindow();
                    }
                }
                break;
            case R.id.tv_field_category:
                if (!ClickUtils.isDoubleClick()) {
                    binding.tvFieldCategory.contentSelect(false, true);
                    if (mFieldCategoryData.size() == 0) {
                        viewModel.getFieldCategory();
                    } else {
                        showFieldCategoryPopWindow();
                    }
                }
                break;
            case R.id.tv_patent_state:
                if (!ClickUtils.isDoubleClick()) {
                    binding.tvPatentState.contentSelect(false, true);
                    if (mPatentStateData.size() == 0) {
                        viewModel.getPatentState();
                    } else {
                        showPatentStatePopWindow();
                    }
                }
                break;
            case R.id.tv_place:
                if (!ClickUtils.isDoubleClick()) {
                    binding.tvPlace.contentSelect(false, true);
                    if (provinceData.size() == 0) {
                        viewModel.getProvinceData();
                    } else {
                        showProvincePopWindow();
                    }
                }
                break;
            case R.id.tv_place2:
                if (!ClickUtils.isDoubleClick()) {
                    binding.tvPlace2.contentSelect(false, true);
                    if (provinceData2.size() == 0) {
                        viewModel.getProvinceData2();
                    } else {
                        showProvincePopWindow2();
                    }
                }
                break;
        }
    }


    //设置行业类型数据
    public void setmTradeCategoryData(List<PickSelectEntity<List<PickSelectEntity>>> datas) {
        mTradeCategoryData.clear();
        mTradeCategoryData.addAll(datas);
        tradeCategoryWindow.setData(mTradeCategoryData, false, false);
        tradeCategoryWindow.showPopwindow(binding.layoutTag, 0, 0);
    }

    public void showTradeCategoryPopWindow() {
        tradeCategoryWindow.setData(mTradeCategoryData, false, false);
        tradeCategoryWindow.showPopwindow(binding.layoutTag, 0, 0);
    }

    //设置领域分类数据
    public void setmFieldCategoryData(List<PickSelectEntity> datas) {
        mFieldCategoryData.clear();
        mFieldCategoryData.addAll(datas);
        fieldCategoryWindow.setData(mFieldCategoryData, false, false);
        fieldCategoryWindow.showPopwindow(binding.layoutTag, 0, 0);
    }

    public void showFieldCategoryPopWindow() {
        fieldCategoryWindow.setData(mFieldCategoryData, false, false);
        fieldCategoryWindow.showPopwindow(binding.layoutTag, 0, 0);
    }

    //设置专利状态数据
    public void setmPatentStateData(List<PickSelectEntity> datas) {
        mPatentStateData.clear();
        mPatentStateData.addAll(datas);
        patentStateWindow.setData(mPatentStateData, false, false);
        patentStateWindow.showPopwindow(binding.layoutTag, 0, 0);
    }

    public void showPatentStatePopWindow() {
        patentStateWindow.setData(mPatentStateData, false, false);
        patentStateWindow.showPopwindow(binding.layoutTag, 0, 0);
    }

    private void showProvincePopWindow() {
        areaPopWindow.showPopwindow(binding.layoutTag, 0, 0);
    }

    //设置省数据
    public void setProvinceDatas(List<PickSelectEntity> datas) {
        provinceData.clear();
        provinceData.addAll(datas);
        areaPopWindow.setData(provinceData);
        areaPopWindow.showPopwindow(binding.layoutTag, 0, 0);
    }

    //设置城市数据
    public void setCityDatas(List<PickSelectEntity> datas) {
        cityData.clear();
        cityData.addAll(datas);
        areaPopWindow.setCityDatas(cityData);
    }

    private void showProvincePopWindow2() {
        areaPopWindow2.showPopwindow(binding.layoutTag, 0, 0);
    }

    //设置省数据
    public void setProvinceDatas2(List<PickSelectEntity> datas) {
        provinceData2.clear();
        provinceData2.addAll(datas);
        areaPopWindow2.setData(provinceData2);
        areaPopWindow2.showPopwindow(binding.layoutTag, 0, 0);
    }

    //设置城市数据
    public void setCityDatas2(List<PickSelectEntity> datas) {
        cityData2.clear();
        cityData2.addAll(datas);
        areaPopWindow2.setCityDatas(cityData2);
    }

    private void setDrwImage(TextView tv, int type) {
        Drawable img_off;
        Resources res = getResources();
        if (type == 0) {
            img_off = res.getDrawable(R.mipmap.icon_up_red);
        } else if (type == 1) {
            img_off = res.getDrawable(R.mipmap.icon_down_red);
        } else {
            img_off = res.getDrawable(R.mipmap.ic_down_arrow_n);
        }
        img_off.setBounds(0, 0, img_off.getMinimumWidth(), img_off.getMinimumHeight());
        tv.setCompoundDrawables(null, null, img_off, null); //设置右图标
    }

    private void setTextViewBg(TextView textView, int bg, int img, int textColor) {
        textView.setBackground(getResources().getDrawable(bg));
        Drawable drawable_n = getResources().getDrawable(img);
        drawable_n.setBounds(0, 0, drawable_n.getMinimumWidth(), drawable_n.getMinimumHeight());
        textView.setCompoundDrawables(null, null, drawable_n, null);
        textView.setTextColor(getResources().getColor(textColor));
    }

    public static void startAction(Context context) {
        Intent intent = new Intent(context, IPActivity.class);
        context.startActivity(intent);
    }
}

